using GamFi.API.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace GamFi.API.Persistence.Configurations;

public class CountryConfiguration : IEntityTypeConfiguration<Country>
{
    /// <inheritdoc />
    public void Configure(EntityTypeBuilder<Country> builder)
    {
        builder.HasKey(x => x.Id);

        builder.Property(p => p.Code)
            .HasMaxLength(4);

        builder.Property(p => p.AlphaTwo)
            .HasMaxLength(2);

        builder.Property(p => p.AlphaThree)
            .HasMaxLength(3);

        builder.HasMany(c => c.Users)
            .WithOne(c => c.Country)
            .HasForeignKey(u => u.CountryId);
    }
}